package com.controller.CategoryController;

import com.entity.Category;
import com.entity.Transaction;
import com.mapper.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
public class CategoryController {

    @Autowired
    private CategoryMapper categoryMapper;

    //通过categoryId查询分类名字
    @GetMapping("/categories/{id}")
    private Category selectByUserId(@PathVariable int id){
        Category category = categoryMapper.selectById(id);
        System.out.println(category);
        return category;
    }

    //查询整个分类表 传递给前端供分类列表页面的table展示
    @GetMapping("/CategoryList/{id}")
    private  List<Category> getCategoryList(@PathVariable int id){
        List<Category> categoryList = categoryMapper.getCategoryList(id);
        return categoryList;
    }
    @PostMapping("/categories")
    private int addCategory(@RequestBody Category category){
        int insert = categoryMapper.insert(category);
        return insert;
    }
    @PutMapping("/categories")
    private int updateCategory(@RequestBody Category category){

        int i = categoryMapper.updateById(category);
        return i;
    }
    @DeleteMapping("/categories/{id}")
    private int deleteCategory(@PathVariable long id){

        int i = categoryMapper.deleteById(id);
        return i;
    }
}
